package com.iknow.xmpp.util;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class SortedList<E>
  implements List<E>
{
  private final List<E> mBackend;
  private final Comparator<? super E> mComparator;

  public SortedList(List<E> paramList, Comparator<? super E> paramComparator)
  {
    this.mComparator = paramComparator;
    this.mBackend = paramList;
    Collections.sort(this.mBackend, paramComparator);
  }

  public void add(int paramInt, E paramE)
  {
    throw new UnsupportedOperationException("add at specific index is not supported in SortedList");
  }

  public boolean add(E paramE)
  {
    int i;
    ListIterator localListIterator = this.mBackend.listIterator();
    if (!(localListIterator.hasNext()))
    {
      this.mBackend.add(paramE);
      i = 1;
    }
    while (true)
    {
      do
        return i;
      while (this.mComparator.compare(paramE, localListIterator.next()) >= 0);
      if (localListIterator.hasPrevious())
        localListIterator.previous();
      localListIterator.add(paramE);
      i = 1;
    }
  }

  public boolean addAll(int paramInt, Collection<? extends E> paramCollection)
  {
    return addAll(paramCollection);
  }

  public boolean addAll(SortedList<? extends E> paramSortedList)
  {
    boolean bool1;
    if (!(paramSortedList.isEmpty()))
      if (this.mBackend.isEmpty())
        bool1 = this.mBackend.addAll(paramSortedList);
    while (true)
    {
      boolean bool2;
      return bool1;
      Object localObject1 = this.mBackend.get(0);
      Object localObject2 = paramSortedList.get(paramSortedList.size() - 1);
      Object localObject3 = this.mBackend.get(this.mBackend.size() - 1);
      Object localObject4 = paramSortedList.get(0);
      if (this.mComparator.compare(localObject2, localObject1) < 0)
        bool2 = this.mBackend.addAll(0, paramSortedList);
      while (true)
      {
        while (true)
        {
          while (true)
            bool1 = bool2;
          if (this.mComparator.compare(localObject4, localObject3) <= 0)
            break;
          bool2 = this.mBackend.addAll(paramSortedList);
        }
        bool2 = addAll(paramSortedList);
      }
      bool1 = false;
    }
  }

  public boolean addAll(Collection<? extends E> paramCollection)
  {
    int i = 0;
    Iterator localIterator = paramCollection.iterator();
    while (true)
    {
      boolean bool;
      do
      {
        if (!(localIterator.hasNext()))
          return i;
        bool = add((Object)localIterator.next());
      }
      while (!(bool));
      i = bool;
    }
  }

  public void clear()
  {
    this.mBackend.clear();
  }

  public boolean contains(Object paramObject)
  {
    return this.mBackend.contains(paramObject);
  }

  public boolean containsAll(Collection<?> paramCollection)
  {
    return this.mBackend.containsAll(paramCollection);
  }

  public boolean equals(Object paramObject)
  {
    return this.mBackend.equals(paramObject);
  }

  public E get(int paramInt)
  {
    return this.mBackend.get(paramInt);
  }

  public int hashCode()
  {
    return this.mBackend.hashCode();
  }

  public int indexOf(Object paramObject)
  {
    return this.mBackend.indexOf(paramObject);
  }

  public boolean isEmpty()
  {
    return this.mBackend.isEmpty();
  }

  public Iterator<E> iterator()
  {
    return new SortedListIterator(this, this.mBackend.listIterator());
  }

  public int lastIndexOf(Object paramObject)
  {
    return this.mBackend.lastIndexOf(paramObject);
  }

  public ListIterator<E> listIterator()
  {
    return new SortedListIterator(this, this.mBackend.listIterator());
  }

  public ListIterator<E> listIterator(int paramInt)
  {
    return new SortedListIterator(this, this.mBackend.listIterator(paramInt));
  }

  public E remove(int paramInt)
  {
    return this.mBackend.remove(paramInt);
  }

  public boolean remove(Object paramObject)
  {
    return this.mBackend.remove(paramObject);
  }

  public boolean removeAll(Collection<?> paramCollection)
  {
    return this.mBackend.removeAll(paramCollection);
  }

  public boolean retainAll(Collection<?> paramCollection)
  {
    return this.mBackend.retainAll(paramCollection);
  }

  public E set(int paramInt, E paramE)
  {
    throw new UnsupportedOperationException("set() is not supported in SortedList");
  }

  public int size()
  {
    return this.mBackend.size();
  }

  public List<E> subList(int paramInt1, int paramInt2)
  {
    return this.mBackend.subList(paramInt1, paramInt2);
  }

  public Object[] toArray()
  {
    return this.mBackend.toArray();
  }

  public <T> T[] toArray(T[] paramArrayOfT)
  {
    return this.mBackend.toArray(paramArrayOfT);
  }

  public String toString()
  {
    return this.mBackend.toString();
  }

  private class SortedListIterator<E>
  implements ListIterator<E>
  {
    private ListIterator<E> mIt;

    SortedListIterator()
    {
      this.mIt = localObject;
    }

    public void add()
    {
      throw new UnsupportedOperationException("add() not supported in SortedList iterator");
    }

    public boolean hasNext()
    {
      return this.mIt.hasNext();
    }

    public boolean hasPrevious()
    {
      return this.mIt.hasPrevious();
    }

    public E next()
    {
      return this.mIt.next();
    }

    public int nextIndex()
    {
      return this.mIt.nextIndex();
    }

    public E previous()
    {
      return this.mIt.previous();
    }

    public int previousIndex()
    {
      return this.mIt.previousIndex();
    }

    public void remove()
    {
      this.mIt.remove();
    }

    public void set()
    {
      throw new UnsupportedOperationException("set () not supported in SortedList iterator");
    }
  }
}